package com.hunktimes.wholesale.ui.pages

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.hunktimes.wholesale.R
import com.hunktimes.wholesale.base.BaseMainFragment
import com.hunktimes.wholesale.base.BasePageFragment
import com.hunktimes.wholesale.databinding.FragmentCollectinBinding
import com.hunktimes.wholesale.extension.setImageUrl
import com.hunktimes.wholesale.mock.goodsWatsons

/**
 * Author: Delete
 * Date: 2020/7/27 9:22
 * Description:
 *
 */

class CollectionFragment : BasePageFragment(R.layout.fragment_collectin) {
    override val titleRes: Int
        get() = R.string.title_collection

    lateinit var viewBinding: FragmentCollectinBinding
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        viewBinding = FragmentCollectinBinding.bind(view)
    }

    override fun onStart() {
        super.onStart()
        initCollection()
    }


    val collectionAdapter = CollectionAdapter()

    fun initCollection() {
        val collectionLm = LinearLayoutManager(requireContext())
        collectionLm.orientation = LinearLayoutManager.VERTICAL
        viewBinding.collectionRcv.layoutManager = collectionLm
        viewBinding.collectionRcv.adapter = collectionAdapter
        val data = mutableListOf<String>()
//        for (i in 1..4) {
//            data.add("收藏收藏$i")
//        }
        repeat(4) {
            data.add(goodsWatsons.random())
        }
        collectionAdapter.data = data

    }

}

class CollectionAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_cart) {
    override fun convert(holder: BaseViewHolder, item: String) {
        val coverIv = holder.getView<ImageView>(R.id.goods_cover_iv)
        coverIv.setImageUrl(item)
    }

}